package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.WxVote;
import com.ruoyi.service.IWxVoteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投票Controller
 * 
 * @author ruoyi
 * @date 2022-03-27
 */
@RestController
@RequestMapping("/vote/vote")
public class WxVoteController extends BaseController
{
    @Autowired
    private IWxVoteService wxVoteService;

    /**
     * 查询投票列表
     */
    @PreAuthorize("@ss.hasPermi('vote:vote:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxVote wxVote)
    {
        startPage();
        List<WxVote> list = wxVoteService.selectWxVoteList(wxVote);
        return getDataTable(list);
    }

    /**
     * 导出投票列表
     */
    @PreAuthorize("@ss.hasPermi('vote:vote:export')")
    @Log(title = "投票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxVote wxVote)
    {
        List<WxVote> list = wxVoteService.selectWxVoteList(wxVote);
        ExcelUtil<WxVote> util = new ExcelUtil<WxVote>(WxVote.class);
        util.exportExcel(response, list, "投票数据");
    }

    /**
     * 获取投票详细信息
     */
    @PreAuthorize("@ss.hasPermi('vote:vote:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wxVoteService.selectWxVoteById(id));
    }

    /**
     * 新增投票
     */
    @PreAuthorize("@ss.hasPermi('vote:vote:add')")
    @Log(title = "投票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxVote wxVote)
    {
        return toAjax(wxVoteService.insertWxVote(wxVote));
    }

    /**
     * 修改投票
     */
    @PreAuthorize("@ss.hasPermi('vote:vote:edit')")
    @Log(title = "投票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxVote wxVote)
    {
        return toAjax(wxVoteService.updateWxVote(wxVote));
    }

    /**
     * 删除投票
     */
    @PreAuthorize("@ss.hasPermi('vote:vote:remove')")
    @Log(title = "投票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxVoteService.deleteWxVoteByIds(ids));
    }
}
